package com.icloud.admin.query;

import com.github.pagehelper.PageInfo;
import com.icloud.admin.query.dto.RoleDTO;
import com.icloud.admin.query.dto.UserDTO;
import com.icloud.admin.query.mapper.RoleDTOMapper;
import com.icloud.admin.query.mapper.UserDTOMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IdentityQueryService {

    @Autowired
    private UserDTOMapper userDTOMapper;

    @Autowired
    private RoleDTOMapper roleDTOMapper;


    public PageInfo<UserDTO> findUsersPaging(int pageNum, int pageSize) {
        return userDTOMapper.findPaging(pageNum, pageSize).toPageInfo();
    }

    public UserDTO findUserById(String userId) {
        return userDTOMapper.findById(userId);
    }

    public UserDTO findCurrentUser(String userId) {
        return userDTOMapper.findById(userId);
    }

    /**
     * 查询用户角色，标识选中或者未选中
     * @param userId
     * @return
     */
    public List<RoleDTO> queryUserRoles(String userId) {
        return roleDTOMapper.findAssignedByUserId(userId);
    }

    public UserDTO findUserByUsername(String username){
       return userDTOMapper.findByUsername(username);
    }


}
